/*
package com.jymj.controller;

import com.jymj.entity.RtExpect;
import com.jymj.entity.view.RtExpectTask;
import com.jymj.service.RtExpectService;
import com.jymj.utils.POIUtil;
import com.jymj.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.util.*;

*/
/**
 * ljj 项目预算
 *//*

@RestController
@RequestMapping("expect")
public class RtExpectController extends AbstractController {

    @Autowired
    private RtExpectService rtExpectService;

    @RequestMapping("queryList/{pjid}")
    @ResponseBody
    public R queryAll(@PathVariable("pjid") Integer pjid) throws Exception {
        Map<String, Object> map = new HashMap<>();
        map.put("pjid", pjid);
        List<RtExpectTask> rtExpects = rtExpectService.queryList(map);
        List<RtExpectTask> treeList = this.getTreeOrgs(rtExpects);
        return R.ok().put("data", treeList);
    }

    */
/**
     * 添加/更新 项目预算表
     *
     * @param rtExpect
     * @return R
     *//*

    @RequestMapping("updateExpect")
    @ResponseBody
    public R updateExpect(@RequestBody RtExpect rtExpect) {
        if (rtExpect.getPjid() != null && rtExpect.getTaskid() != null) {
            if (rtExpect.getId() == null) {
                rtExpectService.save(rtExpect);
            } else {
                rtExpectService.update(rtExpect);
            }
            rtExpectService.updateParentCost(rtExpect);
        }
        return R.ok();
    }

    */
/**
     * 删除 项目预算表
     *
     * @param id
     * @return
     *//*

    @RequestMapping("deleteExpect")
    @ResponseBody
    public R deleteExpect(Integer id) {
        RtExpect rtExpect = rtExpectService.queryObject(id);
        rtExpectService.delete(id);
        rtExpectService.updateParentCost(rtExpect);
        return R.ok();
    }

    */
/**
     * 查询所有 项目预算表
     *
     * @param allOrgs
     * @return List
     * @throws Exception
     *//*

    public List<RtExpectTask> getTreeOrgs(List<RtExpectTask> allOrgs) throws Exception {
        List<RtExpectTask> listParentRecord = new ArrayList<>();
        List<RtExpectTask> listNotParentRecord = new ArrayList<>();
        // 第一步：遍历allOrgs找出所有的根节点和非根节点
        if (allOrgs != null && allOrgs.size() > 0) {
            for (RtExpectTask org : allOrgs) {
                if (0 == org.getPtfatherid()) {
                    listParentRecord.add(org);
                } else {
                    listNotParentRecord.add(org);
                }
            }
        }
        // 第二步： 递归获取所有子节点
        if (listParentRecord.size() > 0) {
            for (RtExpectTask record : listParentRecord) {
                // 添加所有子级
                record.setChildren(this.getChildOrgs(listNotParentRecord, record.getPttaskid()));
            }
        }
        return listParentRecord;
    }

    public List<RtExpectTask> getChildOrgs(List<RtExpectTask> childList, Integer ptfatherid) throws Exception {
        List<RtExpectTask> listParentOrgs = new ArrayList<>();
        List<RtExpectTask> listNotParentOrgs = new ArrayList<>();
        // 遍历childList，找出所有的根节点和非根节点
        if (childList != null && childList.size() > 0) {
            for (RtExpectTask record : childList) {
                // 对比找出父节点
                if (record.getPtfatherid().equals(ptfatherid)) {
                    listParentOrgs.add(record);
                } else {
                    listNotParentOrgs.add(record);
                }
            }
        }
        // 查询子节点
        if (listParentOrgs.size() > 0) {
            for (RtExpectTask record : listParentOrgs) {
                // 递归查询子节点
                record.setChildren(getChildOrgs(listNotParentOrgs, record.getPttaskid()));
            }
        }
        return listParentOrgs;
    }

    */
/**
     * 上传excel文件
     *
     * @param file
     * @param pjid
     * @return R
     * @throws IOException
     *//*

    @RequestMapping("uploadExcelToDb")
    public R uploadExcelToDb(MultipartFile file, Integer pjid) throws IOException {
        //引入工具类的方法
        List<String[]> list = POIUtil.readExcel(file);
        //得到本地时间
        Date d = new Date();
        //创建一个集合存放实体类对象
        List<RtExpect> rtExpectList = new ArrayList<>();
        //遍历整表
        for (int i = 0; i < list.size(); i++) {
            //得到每一行数据
            String[] rows = list.get(i);
            //产生对象
            RtExpect rtExpect = new RtExpect();
            if (i != list.size() - 1) {
                //往对象中放值
                rtExpect.setPjid(pjid);//项目编号
                rtExpect.setRemark((null != (rows[7]) && !"".equals(rows[7])) ? (rows[7]) : null);//备注信息
                rtExpect.setCreatepsn(Integer.parseInt(getUserId().toString()));//创建人id
                rtExpect.setCreatetime(d);//创建时间
                */
/* rtExpect.setUnitid((null != rows[3] && !"".equals(rows[3])) ? rows[3] : null);//单位*//*

                rtExpect.setNum((null != rows[4] && !"".equals(rows[4])) ? (new BigDecimal(rows[4])) : null);//数量
                rtExpect.setUntilPrice((null != rows[5] && !"".equals(rows[5])) ? (new BigDecimal(rows[5])) : null);//单价
                rtExpect.setTotal((null != rows[6] && !"".equals(rows[6])) ? (new BigDecimal(rows[6])) : null);//合计
                rtExpect.setItemid(i);//编号
                //放进集合
                rtExpectList.add(rtExpect);
            }

        }
        //调用业务层方法
        rtExpectService.importSome(rtExpectList);
        return R.ok();
    }

    @RequestMapping("list")
    public R queryByPjid(@RequestParam("pjid") Integer pjid) {
        List<RtExpect> rtExpectList = rtExpectService.selectByPjId(pjid);
        return R.ok().put("data", rtExpectList);
    }

    */
/**
     * 删除
     *
     * @param pjid
     *//*

    @RequestMapping("delete")
    public void delByPjid(@RequestParam("pjid") Integer pjid) {
        rtExpectService.delByPjid(pjid);

    }

    */
/**
     * 下载excel表格
     *
     * @param request
     * @param response
     * @throws IOException
     *//*

    @RequestMapping("downloadExpect")
    public void downloadExpect(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String path = request.getSession().getServletContext().getRealPath("expect") + "/expect.xlsx";
        InputStream ios = new FileInputStream(path);
        response.setHeader("Content-Disposition", "attachment;filename=" + "expect.xlsx");
        byte[] bytes = new byte[1024];
        int len;
        OutputStream ops = response.getOutputStream();
        while ((len = ios.read(bytes)) != -1) {
            ops.write(bytes, 0, len);
        }
        ops.flush();
        ios.close();
        //return R.ok().put("data",path);
    }

}
*/
